package com.anjie.powerproject.repository;

import com.anjie.powerproject.entity.Electricity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface ElectricityRepository extends JpaRepository<Electricity,Integer> {

    @Query(nativeQuery = true, value = "select id, start_time, end_time, price, graph_id, ele_type from electricity where graph_id=?1 order by start_time")
    public List<Electricity> getAllByGraphId(Integer graphId);

//    List<ElectricityBak> getAllByEleTypeAndGraphId(Integer eleType, Integer graphId);

    @Transactional
    @Modifying
    @Query(nativeQuery = true,value = "update electricity set start_time = ?1,end_time = ?2,price = ?3 where id = ?4")
    Integer updateElePrice(String startTime,String endTime,Double price,Integer id);

    @Transactional
    @Modifying
    @Query(nativeQuery = true,value = "update electricity set ele_type = ?1 where id = ?2")
    Integer updateEleType(Integer eleType,Integer id);

    Electricity findElectricityById(Integer id);

    void deleteElectricitiesByGraphId(Integer graphId);
}
